Ext.define('DDMS.controller.Tablet', {
    extend: 'Ext.app.Controller',
    config: {
        refs: {
            usernameCmp: '#tablet-username',
            unitListCmp: '#unit-nestedlist',
            tabletBtnCmp: '#tablet-btn',
            tabletRegisterBtnCmp: '#tablet-register-btn'
        },

        control: {
        	usernameCmp: {
        	  focus: 'usernameCmpFocus'
        	},
        	unitListCmp: {
        	  leafitemtap: 'unitListCmptap'
        	},
        	tabletBtnCmp:{
        	  tap:'tabletBtnCmptap'
        	},
        	tabletRegisterBtnCmp:{
        	  tap:'tabletRegisterBtnCmptap'
        	}
        }
    },
    usernameCmpFocus: function(obj,e, eOpts) {
    	var unitCmp=Ext.getCmp('unit');
    	if (!unitCmp){
    	    unitCmp=Ext.create('DDMS.view.Unit');
    	}
        Ext.Viewport.add(unitCmp);
        unitCmp.show();
    },
    unitListCmptap: function(obj, list, index, target, record, e, eOpts) {
    	Ext.getCmp('tablet-username').setValue(record.get('text'));
    	Ext.getCmp('unit').hide();
    },
    tabletRegisterBtnCmptap:function (){
    	var regCmp=Ext.getCmp('register');
    	if (!regCmp){
    	    regCmp=Ext.create('DDMS.view.Register');
    	}else{
	  	  	regCmp.reset();
	  	}
        Ext.Viewport.animateActiveItem(regCmp,{
            type: 'slide',
            direction: 'left',
            duration: 250
    	});
    },
    tabletBtnCmptap: function(){
//		var un=Ext.getCmp('username').getValue();
//		var ps=Ext.getCmp('password').getValue();
//		if (un==''){
//		  Ext.Msg.alert("信息提示","请填写登录账户");return;
//		}
//		if (ps==''){
//		  Ext.Msg.alert("信息提示","请填写登录密码");return;
//		}
		var doMain=Ext.getCmp('domainTab');
		if (!doMain){
			doMain=Ext.create('DDMS.view.DomainTab');
		}
	    Ext.Viewport.animateActiveItem(doMain,{
	        type: 'pop',
	        duration: 250
		});
    }
});